from sqlalchemy.orm import Session
from faker import Faker
from .bs_models import BaseStation, LTEFreqRecord, NRFreqRecord
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey
from sqlalchemy.orm import sessionmaker, relationship, declarative_base
from typing import Generator


fake = Faker("zh_CN")


def fake_base_station(db: Session):
    for _ in range(100):
        base_station = BaseStation(
            name=fake.company(),
            longitude=fake.longitude(),
            latitude=fake.latitude(),
            address=fake.address(),
            is_rooftop=fake.random_int(min=0, max=1),
        )
        db.add(base_station)
    db.commit()


def fake_lte_freq(db: Session):
    base_stations = db.query(BaseStation).all()
    for base_station in base_stations:
        for _ in range(4):
            lte_freq_record = LTEFreqRecord(
                point_number=fake.numerify("#\#"),
                point_description=fake.sentence(),
                line_max=fake.pyfloat(min_value=0, max_value=100),
                line_min=fake.pyfloat(min_value=0, max_value=100),
                result_1=fake.pyfloat(min_value=0, max_value=100),
                result_2=fake.pyfloat(min_value=0, max_value=100),
                result_3=fake.pyfloat(min_value=0, max_value=100),
                result_4=fake.pyfloat(min_value=0, max_value=100),
                result_5=fake.pyfloat(min_value=0, max_value=100),
                result_avg=fake.pyfloat(min_value=0, max_value=100),
                standard_deviation=fake.pyfloat(min_value=0, max_value=100),
                mobile_value=fake.pyfloat(min_value=0, max_value=100),
                unicom_value=fake.pyfloat(min_value=0, max_value=100),
                telecom_value=fake.pyfloat(min_value=0, max_value=100),
                telegraph_value=fake.pyfloat(min_value=0, max_value=100),
                other_value=fake.pyfloat(min_value=0, max_value=100),
                is_large_value_point=fake.boolean(),
                longitude=fake.longitude(),
                latitude=fake.latitude(),
                image_path=fake.file_path(),
                remarks=fake.paragraph(),
                recorder=fake.name(),
                base_station_id=base_station.id,
            )
            db.add(lte_freq_record)
    db.commit()
